package com.cloud.pole.shop.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.pole.api.advert.AdvertApi;
import com.cloud.pole.api.msg.MsgNoticeApi;
import com.cloud.pole.api.param.PicklistApi;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.feign.IAdvertService;
import com.cloud.pole.feign.INoticeService;
import com.cloud.pole.feign.IParamPickListService;
import com.cloud.pole.shop.biz.goods.ShopGoodsCategoryBiz;
import com.cloud.pole.shop.biz.goods.ShopGoodsGroupBiz;
import com.cloud.pole.shop.biz.goods.ShopGoodsGroupRecommBiz;
import com.cloud.pole.shop.biz.goods.ShopGoodsPromotionBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsComponentBiz;
import com.cloud.pole.shop.constant.ShopCommonConstant;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsCategory;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsGroup;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsGroupRecomm;
import com.cloud.pole.shop.model.entity.shops.ShopShopsComponent;
import com.cloud.pole.shop.model.vo.IndexVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionByTypeVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionVo;
import com.cloud.pole.shop.service.IndexService;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

/*
*2019年1月30日
*cloud-user
*author:frank-chen
*/
@Slf4j
@Service
public class IndexServiceImpl implements IndexService{
	
	@Autowired
	private IAdvertService advertService;
	
	@Autowired
	private IParamPickListService paramPickListService;
	
	@Autowired 
	private ShopGoodsCategoryBiz shopGoodsCategoryBiz;
	
	@Autowired 
	private ShopGoodsPromotionBiz shopGoodsPromotionBiz;
	
	@Autowired 
	private INoticeService noticeService;
	
	@Autowired 
	private ShopGoodsGroupBiz shopGoodsGroupBiz;
	
	@Autowired 
	private ShopShopsComponentBiz shopShopsComponentBiz;
	
	@Override
	public IndexVo getIndexData(String token, Integer shopId)throws Exception{
		IndexVo indexVo = new IndexVo();
		//轮播广告
		ApiRestResponse<List<AdvertApi>> advertResponse = 
				advertService.getShopAdvertList(ShopCommonConstant.WEB_SHOP_ADVERT_INDEX, shopId);
		if(advertResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(advertResponse.getStatus(), advertResponse.getMessage());
		}
		List<AdvertApi> advertList = advertResponse.getData();
		indexVo.setAdvertVoList(advertList);

		//产品分组推荐
		List<ShopGoodsGroup> recommList = 
				shopGoodsGroupBiz.getListByShop(shopId, ShopCommonConstant.SHOP_GOODS_GROUP_RECOMM_INDEX);
		indexVo.setShopGoodsGroupList(recommList);
		
		//店铺模板
		ShopShopsComponent shopShopsComponent = shopShopsComponentBiz.selectByShopId(shopId);
		indexVo.setShopShopsComponent(shopShopsComponent);
		
		//系统通知
//		ApiRestResponse<List<MsgNoticeApi>> noticeResponse =  noticeService.getSysNoticeList(1, 4);
//		if(noticeResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
//			throw new BaseException(noticeResponse.getStatus(), noticeResponse.getMessage());
//		}
//		indexVo.setMsgNoticeList(noticeResponse.getData());
		
		return indexVo;
	}

	@Override
	public List<ShopGoodsPromotionVo> getGoodsPromotion(String token, Integer componentId) throws Exception {
		return shopGoodsPromotionBiz.selectShopGoodsPromotionVoListByMap(componentId);
	}
}
